<template>
  <div class="search-box">
    <i class="ls-search-wrap"></i>
    <input rel="input" v-model="input" @input="transKeyWords" class="box" :placeholder="placeholder"/>
    <i @click="clear" v-show="input" class="off-search material-icons"></i>
  </div>
</template>

<script type="text/ecmascript-6">
 import {debounce} from 'common/js/util'
 import {mapMutations} from 'vuex'
export default {
  props: {
    placeholder: {
      type: String,
      default: 'Search | Meet50off'
    }
  },
  data() {
    return {
      input: ''
    }
  },
  created() {
    this.$watch('input', debounce((newInput) => {
      this.$emit('input', newInput)
    }, 200))
  },
  methods: {
    transKeyWords() {
      this.setinput(this.input)
    },
    clear() {
      this.input = ''
    },
    // setQuery(query) {
    //   this.input = input
    // },
    blur() {
      this.$refs.input.blur()
    },
    // blur() {
    //   this.$refs.query.blur()
    // }
    ...mapMutations({
      setinput:'SET_INPUT'
    })
  },
  // created() {
  //   this.$watch('query', debounce((newQuery) => {
  //     this.$emit('query', newQuery)
  //   }, 200))
  // }
}
</script>

<style scoped lang="stylus" rel="stylesheet/stylus">
  @import "~common/stylus/variable"
  @import "~common/stylus/mixin"
  .search-box
    display: flex
    align-items: center
    box-sizing: border-box
    width: 100%
    padding: 0 6px
    height: 40px
    background: $color-white
    border-radius: 6px
    position : relative
    margin-right: 5px;
    .ls-search-wrap
      position: absolute;
      line-height: 1em;
      width: 20px;
      height: 20px;
      background-repeat: no-repeat;
      background-position: 0 0;
      background-size: 20px
      background-image: url(../../../static/img/Magnifier-icon.png);

    .box
      flex: 1
      line-height: 18px
      outline: none;
      border: none;
      padding: 10px 0 10px 0;
      text-indent: 22px
      font-size: $font-size-medium
      width: 100%;
      &::placeholder
        color: #bbb
    .off-search
      position absolute
      right 8px
      top 10px
      font-size: 22px
      color: $color-dialog-background
    .off-search:before
      content: "\E888";
</style>
